<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 配送员评论管理
 * Class Comment
 */
class Comment extends MY_Controller {
	/**
	 * 产品评论模型
	 * @var DlnCommentModel
	 */
	public $mComment;
	
	public function __construct(){
		parent::__construct();	
		$this->loadModel('DlnCommentModel', 'mComment', 'deliveryman');
	}

	/**
	 * 首页
	 */
	public function index(){
		$data = array(
            'title'=>'评论管理',
		);
		$this->view('deliveryman/comment/home', $data, 'datatable,select2,validation,datepicker');
	}
	
	/**
	 * 获取列表
     * @author heyu
	 */
	public function getList(){
		$data = $this->mComment->adminGetList();
		foreach ($data['data'] as $k=>$v){
            $data['aaData'][$k][] = $v['m_name'];
            $data['aaData'][$k][] = $v['deliveryman'];
			$data['aaData'][$k][] = '<textarea readonly class="form-control remaks-item content textarea_height" style="height: 36px;">'.
                trim($v['tags'], ',').'</textarea>';
			$data['aaData'][$k][] = $v['score'];
			$data['aaData'][$k][] = date('Y-m-d H:i:s',$v['addtime']);
			$data['aaData'][$k][] = '';
		}
		unset($data['data']);
		echo json_encode($data);
	}

    /**
     * 查看评论详情
     * @author heyu
     */
    public function getInfo(){
        //表单验证
        $vConf = array(
            array('id', 'id', 'required|is_natural_no_zero'),
        );
        $this->formDataValidation($vConf);
        $id = (int)post('id');
        $info = $this->mComment->getInfo($id);
        if (!$info){
            $this->ajaxReturn(0, '信息不存在');
        }
        $this->ajaxReturn(1, '', $info);
    }
	
	//////////////////////////////////////////////////////////////////
	//+--------------------------------------------------------------
	//|	商品评论
	//+--------------------------------------------------------------
	
	/**
	 * 删除评价
	 */
	public function rmComment(){
        //表单验证
        $vConf = array(
            array('id', 'id', 'required|is_natural_no_zero'),
        );
        $this->formDataValidation($vConf, array('id' => get('id')));
		$id = (int)get('id');
        $info = $this->mComment->getInfo($id);
        if (!$info){
            $this->ajaxReturn(0, '信息不存在或已删除');
        }
		if ( ! $this->mComment->removeComment($id)){
			 $this->ajaxReturn(0,'删除失败');
		}
		$this->ajaxReturn(1,'删除成功');
	}

}
